home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
JCSM Shareware Collection 1997 February
/
JCSM Shareware Collection February 1997 Best of (JCS Marketing)(February 1997).bin
/
PRGTOOLS
/
TN2.ZIP
/
COCO.T
< prev
next >
Wrap
Text File
|
1996-11-15
|
897b
|
49 lines
%
% "coco.t" computes combinatorial coefficients
%
% Sample program for the T Interpreter by:
%
% Stephen R. Schmitt
% 962 Depot Road
% Boxborough, MA 01719
%
var i, selections, elements : int
var answer : real
program
prompt "Number of selections? "
get selections
prompt "Out of how many elements? "
get elements
answer := elements
for i := 1 ... selections - 1 do
elements := elements - 1
answer := answer * elements
end for
put "Nonunique combinations = ", answer
answer := answer / factorial( selections )
put "Unique combinations = ", answer
end program
function factorial( n : int ) : real
var result : real
result := 1
loop
exit when n <= 0
result := result * n
n := n - 1
end loop
return result
end function